package com.ruoyi.lvlian.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.lvlian.dto.InvoiceDetailsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lvlian.mapper.InvoiceDetailsMapper;
import com.ruoyi.lvlian.domain.InvoiceDetails;
import com.ruoyi.lvlian.service.IInvoiceDetailsService;

/**
 * 发票项目名称明细Service业务层处理
 *
 * @author ruoyi
 * @date 2024-07-26
 */
@Service
public class InvoiceDetailsServiceImpl implements IInvoiceDetailsService {
    @Autowired
    private InvoiceDetailsMapper invoiceDetailsMapper;

    /**
     * 查询发票项目名称明细
     *
     * @param id 发票项目名称明细主键
     * @return 发票项目名称明细
     */
    @Override
    public InvoiceDetails selectInvoiceDetailsById(String id) {
        return invoiceDetailsMapper.selectInvoiceDetailsById(id);
    }

    /**
     * 查询发票项目名称明细列表
     *
     * @param invoiceDetails 发票项目名称明细
     * @return 发票项目名称明细
     */
    @Override
    public List<InvoiceDetails> selectInvoiceDetailsList(InvoiceDetailsDto invoiceDetails) {
        return invoiceDetailsMapper.selectInvoiceDetailsList(invoiceDetails);
    }

    /**
     * 新增发票项目名称明细
     *
     * @param invoiceDetails 发票项目名称明细
     * @return 结果
     */
    @Override
    public int insertInvoiceDetails(InvoiceDetails invoiceDetails) {

        invoiceDetails.setId(MD5Utils.md5(invoiceDetails.getInvoiceNum() + invoiceDetails.getGoodsName()));

        invoiceDetails.setCreateDate(DateUtils.getCurrentTime());

        return invoiceDetailsMapper.insertInvoiceDetails(invoiceDetails);
    }

    /**
     * 修改发票项目名称明细
     *
     * @param invoiceDetails 发票项目名称明细
     * @return 结果
     */
    @Override
    public int updateInvoiceDetails(InvoiceDetails invoiceDetails) {

        int updateResult = invoiceDetailsMapper.updateInvoiceDetails(invoiceDetails);
        if (0 == updateResult) {
            updateResult = insertInvoiceDetails(invoiceDetails);
        }

        return updateResult;
    }

    /**
     * 批量删除发票项目名称明细
     *
     * @param ids 需要删除的发票项目名称明细主键
     * @return 结果
     */
    @Override
    public int deleteInvoiceDetailsByIds(String[] ids) {
        return invoiceDetailsMapper.deleteInvoiceDetailsByIds(ids);
    }

    /**
     * 删除发票项目名称明细信息
     *
     * @param id 发票项目名称明细主键
     * @return 结果
     */
    @Override
    public int deleteInvoiceDetailsById(String id) {
        return invoiceDetailsMapper.deleteInvoiceDetailsById(id);
    }
}
